package logic

import (
	"context"
	"fmt"
	"ykone/models/mysql"

	"ykone/ykonerpc/internal/svc"
	"ykone/ykonerpc/ykonerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProduceShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProduceShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProduceShowLogic {
	return &ProduceShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProduceShowLogic) ProduceShow(in *ykonerpc.ProduceShowRequest) (*ykonerpc.ProduceShowResponse, error) {
	// todo: add your logic here and delete this line

	var produce mysql.Produce
	mysql.DB.Debug().Where("id = ?", in.Id).Find(&produce)

	if produce.ID == 0 {
		return nil, fmt.Errorf("id不存在,请重新输入")
	}

	return &ykonerpc.ProduceShowResponse{
		ProductName:  produce.ProductName,
		ProductStore: produce.ProductStore,
		Price:        produce.Price,
		Img:          produce.Img,
		Id:           in.Id,
	}, nil
}
